/**
 * Created by Xiaoming on 2017/9/5.
 */
angular.module('module.order')
    .controller('OrderDetailController', OrderDetailController);
OrderDetailController.$inject = ['$stateParams', '$state', 'OrderService'];
function OrderDetailController($stateParams, $state, OrderService) {
    var vm = this;
    vm.refund = refund;
    vm.anotherOne = anotherOne;
    vm.sureRefund = sureRefund;
    vm.dismiss = dismiss;
    vm.unifyrefund = unifyrefund;
    loadCart(true, "loader");
    OrderService.getOrderByOrderId($stateParams.orderid).$promise.then(function (order) {
        vm.order = order;
        if(order.extField){
            vm.extField = JSON.parse(order.extField);
        }else{
            vm.extField = {};
        }
        loadCart(false, "loader");
    });


    //申请退款功能
    function unifyrefund(){
        $(".unifyrefund_html").fadeIn();
    }
    function dismiss(){
        $(".unifyrefund_html").fadeOut();
    }
    function sureRefund(){
        OrderService.updateOrderById(vm.order);
    }
    //再来一单功能
    function anotherOne(shop) {
        $state.go("store",{shopid:shop.shopid,appid:$stateParams.appid,deskid:$stateParams.deskid});
    }
    vm.reasonList = [
        {
            text:"商品已卖完"
        }, {
            text:"商家态度不好"
        }, {
            text:"买错商品"
        }, {
            text:"其他"
        },
    ];
    vm.reason = vm.reasonList[0];
    vm.explain = "";
    function refund(){
        vm.extField.refundReason = vm.reason.text + "," + vm.explain;
        vm.order.extField = JSON.stringify(vm.extField);
        vm.order.paystate = 21;
        OrderService.updateOrderById(vm.order,function(order){
            input_alert("申请已提交",2000);
            vm.dismiss();
        });
    }
}